feat: QALB-7 cognitive architecture + frontend integration - #26
Conversation
…gration Complete implementation of the 7-layer Quranic Cognitive Architecture: Backend — QALB-7 Pipeline (13 new modules): - Fitrah: innate ethical guardrails (NO_HARM, TRUTH, JUSTICE) - Nafs Triad: 3-voice deliberation (Ammara/Lawwama/Mutmainna) - Qalb Processor: cardiac oscillation modulating LLM temperature/tokens - Fu'ad: Bayesian conviction engine (impression→belief→conviction) - Lubb: metacognition (compress, coherence check, bias detection) - Developmental Gate: 7-stage capability gating (Nutfah→Khalq Akhar) - Causal Engine: Pearl's 3-rung causal ladder - Self-Healing: Lawwama immune system with adaptive checkpoints - Parallel Agents, Imagination, Creativity, Dream Engine - Shura Council: multi-agent consultation Backend — Memory Architecture (3 new modules): - Lawh al-Mahfuz: immutable memory with triple-checksum integrity - Memory Pyramid: unified 5-layer query engine - Living Memory: adaptive memory lifecycle Backend — Wiring & Fixes: - Wire all QALB-7 modules into BaseAgent.execute() - Replace 10 hardcoded rules with proper module calls - Surface cognitive metadata in WS chat_complete messages - XML tool-call fallback parser for MiniMax-style models - Fix async coroutine issue in memory_pyramid.py - SuperAgent starts at nafs_level=3 (Mudghah) Frontend — Cognitive UI: - CognitiveBar: expandable pill row under assistant messages (Qalb state, Yaqin level, Lubb quality, Ruh energy, Nafs badge) - AgentCard: Ruh energy bar with color gradient - Full UI redesign: component extraction, dark mode, responsive layout - CognitiveMetadata TypeScript types Docs & Config: - README: full QALB-7 architecture docs, module tables, stage diagram - docs/index.html: QALB-7 deep dive, updated project structure - .gitignore: add .vault.key and .mcp.json - New skills: linode_cloud, ssh_remote Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1e61c899c0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| agent.ai_model = req.model_override | ||
| agent.ai_client = override_provider |
There was a problem hiding this comment.
Avoid mutating shared agent model state during overrides
The per-message override path mutates agent.ai_model/agent.ai_client on the shared agent instance before awaiting agent.execute, which creates a race when two chats hit the same agent concurrently. In an interleaving where request A and B both override models, A can restore mid-flight while B is still executing, and B can then restore a stale value, causing responses to run on the wrong model and leaving the agent in an unintended model state after completion.
Useful? React with 👍 / 👎.
| agent.ai_model = req.model | ||
| provider_obj = create_provider(model=req.model) | ||
| if provider_obj: |
There was a problem hiding this comment.
Validate provider before accepting agent model updates
This endpoint sets agent.ai_model even when create_provider(model=req.model) fails, so a model update can return success while leaving the old client attached. A common case is selecting a model that auto-resolves to a provider with no configured key; subsequent requests then run the old provider against the new model id and fail at inference time.
Useful? React with 👍 / 👎.
| "role": agent.role, | ||
| "nafs_level": agent.nafs_level, | ||
| "capabilities": list(agent.tools.keys()), | ||
| "config": agent.config, |
There was a problem hiding this comment.
Persist updated model in agent profile configuration
The update flow saves agent.config back to storage but never writes req.model into that config, so model changes made via this endpoint are not durable. On restart, agent reconstruction reads profile["config"] and silently reverts to the old model, which makes model updates appear to “randomly” disappear after process restarts.
Useful? React with 👍 / 👎.
Summary
<invoke>XML instead of structured APIChanges
backend/core/*.pybackend/memory/*.pybackend/reasoning/causal_engine.pybackend/agents/*.pybackend/agents/base.pybackend/providers.pybackend/api/main.pyfrontend/src/types.tsbackend/skills/builtin/*.py66 files changed, +16,853 / -2,036 lines
Test plan
cd frontend && npm run buildpasses cleancd backend && python -c "from agents.base import BaseAgent"imports all QALB-7 modules🤖 Generated with Claude Code